const GuToken = artifacts.require("guToken.sol");
const Exchange = artifacts.require("Exchange.sol");
const ETHER_ADDRESS = "0x0000000000000000000000000000000000000000";

const fromWei = (value) => {
  return web3.utils.fromWei(value.toString(), "ether");
}

const toWei = (number) => {
  return web3.utils.toWei(number.toString(), "ether");
}

module.exports = async function (callback) {
 const gutoken = await GuToken.deployed();
 const exchange = await Exchange.deployed();
 const accounts = await web3.eth.getAccounts();

  await exchange.depositEther({
    from: accounts[0],
    value: toWei(10)
  });

  let res =await exchange.tokens(ETHER_ADDRESS, accounts[0])
  console.log(fromWei(res));

  //授权
  await gutoken.approve(exchange.address, toWei(100000), {
    from: accounts[0]
  });

  await exchange.depositToken(gutoken.address, toWei(100000), {
    from: accounts[0]
  });

  let res1 =await exchange.tokens(gutoken.address, accounts[0])
  console.log(fromWei(res1));

  callback();

}


